package com.ylbh.modules.goods.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.goods.dto.SpecIficationDTO;
import com.ylbh.common.pojo.goods.dto.SpecPropertyDTO;
import com.ylbh.common.pojo.goods.dto.SubGoodsClassDTO;
import com.ylbh.common.pojo.goods.vo.SpecIficationVO;
import com.ylbh.common.pojo.goods.vo.SpecPropertyVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.goods.service.GoodsSpecService;
import com.ylbh.modules.sys.controller.AbstractController;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author mgh
 */
@RestController
@RequestMapping("goods/spec")
public class ShoppingSpecController extends AbstractController {
    @Autowired
    private GoodsSpecService goodsSpecService;

    @ApiOperation("商品规格信息列表")
    @RequestMapping("queryGoodsSpecList")
    @RequiresPermissions("goods:spec:queryGoodsSpecList")
    public CommonResult<PageUtils> queryGoodsSpecList(PageDTO pageDTO){
        PageUtils list = goodsSpecService.queryGoodsIficationList(pageDTO);
        return Ref.ok(list);
    }


    @SysLog("添加商品规格")
    @ApiOperation("添加商品规格")
    @RequestMapping("add")
    @RequiresPermissions("goods:spec:add")
    public CommonResult add(@RequestBody SpecIficationDTO specIficationDTO){
        goodsSpecService.add(specIficationDTO);
        return Ref.ok();
    }

    @SysLog("修改商品规格")
    @ApiOperation("修改商品规格")
    @RequestMapping("modifyById")
    @RequiresPermissions("goods:spec:modify")
    public CommonResult modifyById(@RequestBody SpecIficationDTO specIficationDTO){
        goodsSpecService.modifyById(specIficationDTO);
        return Ref.ok();
    }

    @ApiOperation("查询规格属性")
    @RequestMapping("queryPropertyByIficationIdList")
    @RequiresPermissions("goods:spec:queryGoodsSpecList")
    public CommonResult<List<SpecPropertyVO>> queryPropertyByIficationIdList(@RequestBody Integer IficationId){
        List<SpecPropertyVO> list = goodsSpecService.queryPropertyByIficationIdList(IficationId);
        return Ref.ok(list);
    }

    @SysLog("添加商品规格属性")
    @ApiOperation("添加商品规格属性")
    @RequestMapping("addProperty")
    @RequiresPermissions("goods:spec:add")
    public CommonResult addProperty(@RequestBody SpecPropertyDTO specPropertyDTO){
        goodsSpecService.addProperty(specPropertyDTO);
        return Ref.ok();
    }

    @SysLog("修改商品规格属性")
    @ApiOperation("修改商品规格属性")
    @RequestMapping("modifyPropertyById")
    @RequiresPermissions("goods:spec:modify")
    public CommonResult modifyPropertyById(@RequestBody SpecPropertyDTO specPropertyDTO){
        goodsSpecService.modifyPropertyById(specPropertyDTO);
        return Ref.ok();
    }
}
